﻿@{
    ViewBag.Title = "学期开课管理";
    Layout = "~/Views/Shared/_GridCommonLayout.cshtml";
}


<!--begin grid code-->


<section id="widget-grid" class="">
    <div class="row">



        <!--Operation-->
        <div class="heading-buttons">


            <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
                <h1 class="page-title txt-color-blueDark"><i class="fa fa-tags "></i>
                    课程开设管理			
                </h1>
            </div>
            <div class="buttons pull-right">

                <button type="button" class="btn btn-success btn-labeled "
                    data-bind="click: $root.showAddBefore">
                    <span class="btn-label"><i class="glyphicon glyphicon-plus"></i>
                    </span>添加记录</button>

                <button type="button" class="btn btn-primary btn-labeled "
                    data-bind="click: $root.onDataDeleting">
                    <span class="btn-label"><i class="glyphicon glyphicon-remove"></i>
                    </span>批量删除</button>


            </div>
            <div style="clear: both;">
            </div>
        </div>
        <!--/Operation-->




        <!--Search-->
        <div class="filter-bar">
            <form id="formSearch">
                <div class="lbl glyphicons search" style="cursor: pointer;" data-bind="click: $root.search">
                    <i></i>筛选
                </div>

                <div>
                    <label>课程名:</label>
                    <div class='input-append'>
                        <input id='txtbSrSCourseName' name='txtbSrSCourseName' type='text' placeholder='' class='input-mini' style='width: 120px;' />
                    </div>
                </div>
                <div>
                    <label>学年学期:</label>
                    <div class='input-append'>
                        <input id='txtbSrSTeamName' name='txtbSrSTeamName' type='text' placeholder='' class='input-mini' style='width: 120px;' />
                    </div>
                </div>
                <div>
                    <label>老师姓名:</label>
                    <div class='input-append'>
                        <input id='txtbSrSTeacharName' name='txtbSrSTeacharName' type='text' placeholder='' class='input-mini' style='width: 120px;' />
                    </div>
                </div>


                <div class="clearfix">
                </div>
            </form>
        </div>
        <!--/search-->



        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
            <div id="wid-id-0" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-editbutton="false">
                <header>
                    <span class="widget-icon"><i class="fa fa-table"></i></span>
                    <h2>开设的课程</h2>
                </header>
                <div style="margin-top: 35px;">
                    <div class="jarviswidget-editbox"></div>
                    <div class="widget-body no-padding">
                        <div role="grid" id="providerGrid" class="dataTables_wrapper form-inline">
                            <div class="table-responsive">

                                <div class="dt-wrapper" style="overflow-y: auto;">
                                    <table class="table table-striped table-bordered table-hover checkboxs">
                                        <!--table head-->
                                        <thead>
                                            <tr>
                                                <th style="width: 1%">
                                                    <input type="checkbox" value="0" />
                                                </th>
                                                <!-- ko foreach: headers -->
                                                <th class="center ">
                                                    <a href="#" data-bind="text: displayText@*, click: $root.sort*@" style="color: black"></a>
                                                    <i class="icon-circle-arrow-up" data-bind="    visible: value == $root.orderBy() && $root.isAsc()"></i>
                                                    <i class="icon-circle-arrow-down" data-bind="    visible: value == $root.orderBy() && !$root.isAsc()"></i>
                                                </th>
                                                <!-- /ko -->
                                                <th class="center" style="width: 60px">操作
                                                </th>
                                            </tr>
                                        </thead>
                                        <!--/table head-->
                                        <!--table body(Provider list)-->
                                        <tbody data-bind="foreach: recordSet">
                                            <tr class="selectable" onclick="">
                                                <td class="center">
                                                    <input type="checkbox" name="userSelector" data-bind="value: Id" />
                                                    <input type="hidden" data-bind="value: Id, attr: { id: Id }" />
                                                </td>

                                                <td class='center'><strong data-bind='text: Id'></strong></td>
                                                <td class='center'><strong data-bind='text: ICourseId'></strong></td>
                                                <td class='center'><strong data-bind='text: SCourseName'></strong></td>
                                                <td class='center'><strong data-bind='text: STeamName'></strong></td>
                                                <td class='center'><strong data-bind='text: STeacharName'></strong></td>
                                                <td class='center'><strong data-bind='text: STeacharCode'></strong></td>


                                                <td class="center">
                                                    <a href="#" class="btn-action glyphicons pencil btn-success" data-bind="click: $root.showUpdateModal">
                                                        <i></i></a>
                                                </td>
                                            </tr>
                                        </tbody>
                                        <!--/table body( Provider list)-->

                                    </table>

                                </div>


                                <!-- 分页 -->
                                <ul class="pagination pagination-alt">
                                    <li>
                                        <a data-bind="click: firstPage"><i class="fa fa-fast-backward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: prevPage"><i class="fa  fa-backward  "></i></a>
                                    </li>
                                    <li>
                                        <a>
                                            <input id="toPage" type="text" data-bind="value: pageIndex, event: { change: $root.changePageIndex }" style="width: 25px;" />
                                            /共<span data-bind="html: totalPages"></span>页 
                                        </a>
                                    </li>
                                    <li>
                                        <a data-bind="click: nextPage"><i class="fa fa-forward "></i></a>
                                    </li>
                                    <li>
                                        <a data-bind="click: lastPage"><i class="fa fa-fast-forward "></i></a>
                                    </li>
                                </ul>

                                <div class="dt-top-row total  ">
                                    当前记录共：<span data-bind="html: totalCount"></span>条
                                </div>
                                <!--end 分页-->
                            </div>

                            <!-- /分页 -->

                        </div>

                        <!-- /分页 -->
                    </div>
                </div>

            </div>
        </article>
    </div>
    <!--end row-->
</section>


<!--DeanOpenCourse详细对话框-->
<div id="DeanOpenCourseMessageModal" class="modal fade" id="ProviderMessageModal" tabindex="-1" role="dialog"
    aria-labelledby="DeanOpenCourseMessageModalLabel" aria-hidden="true">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3>课程开设详细信息</h3>
        </div>

        <div class="modal-body">
            <input type='hidden' id='txtbID' name='txtbID' />
            <form class="smart-form" id="formDeanOpenCourse">

                <fieldset>
                    <section>
                        <label class='label'>课程(请输入课程名):</label>
                        <label class='input'>
                            <input type='text' id='txtbSCourseName' name='txtbSCourseName' placeholder='' class='typeahead span10' />
                        </label>
                    </section>

                    <section>
                        <label class='label'>学年学期(请输入):</label>
                        <label class='input'>
                            <input type='text' id='txtbSTeamName' name='txtbSTeamName' placeholder='' class='typeahead span10' />
                        </label>
                    </section>

                    <section>
                        <label class='label'>教师师姓名(请输入):</label>
                        <label class='input'>
                            <input type='text' id='txtbSTeacharName' name='txtbSTeacharName' placeholder='' class='typeahead span10' />
                        </label>
                    </section>
                </fieldset>
            </form>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">
                取消</button>
            <button id="btnSaveOrUpdateModel" class="btn btn-primary" aria-hidden="true" data-bind=" click: onDataAddingOrUpdate">
                确定</button>
        </div>
    </div>
    <!--end div content-->
</div>
<!--/详细DeanOpenCourse对话框-->

@section script{

    
    <script type="text/javascript">

        var sCourseCode;
        var gdViewModel;
        $(function () {
            $._messengerDefaults = {
                extraClasses: 'messenger-fixed messenger-theme-future messenger-on-bottom messenger-on-right'
            }; //默认提示位置;


            var options = {

                dialogId: "DeanOpenCourseMessageModal", //添加对话框

                pageSize: 20, //分页大小
                hidId: $("#txtbID"),
                SaveUpdateBtn: $("#btnSaveOrUpdateModel"),
                frmElement: $("#formDeanOpenCourse"),

                //节点数据
                NodeValue: ko.observable({

                    Id: 0,
                    ICourseId: 0,
                    SCourseName: '',
                    ITeamId: 0,
                    STeamName: '',
                    ITeacherId: 0,
                    STeacharName: '',
                    STeacharCode: ''


                }),


                //用户列表Grid头部列名称
                headers: [


     { displayText: 'ID', value: 'Id', width: 'auto' },
     { displayText: '课程代号', value: 'ICourseId', width: 'auto' },
     { displayText: '课程名', value: 'SCourseName', width: 'auto' },
     { displayText: '开课时间', value: 'STeamName', width: 'auto' },
     { displayText: '开课教师', value: 'STeacharName', width: 'auto' },
     { displayText: '教师工号', value: 'STeacharCode', width: 'auto' }


                ],

                //默认的排序方式
                defaultOrderBy: "Id",
                //用户查询URL
                dataQueryUrlAccessor: function () {
                    return "/api/DeanOpenCourse/GetByPage";
                },

                //添加用户URL
                dataAddUrlAccessor: function () {
                    return appendQueryString("/api/SysUser/AddOpenCourse", { sCourseCode: sCourseCode });
                },
                dataUpdateAccessor: function (key) {

                    AddOrUpdate();
                    return appendQueryString("/api/SysUser/UpdateOpenCourse/" + key, { sCourseCode: sCourseCode });
                },
                dataNodeSelect: function (id) {
                    return "/api/DeanOpenCourse/get/" + id;
                },

                dataDeleteAccessor: function (data) {
                    var userIDs = "";
                    var check = $("input:checked");  //得到所有被选中的checkbox
                    check.each(function (i) {        //循环拼装被选中项的值
                        userIDs = userIDs + ',' + $(this).val();
                    });
                    //清除多余的分割号
                    userIDs = dropRsplit(userIDs, ",");
                    if (userIDs != "") {
                        return appendQueryString("/api/DeanOpenCourse/DeleteIds", { ids: userIDs });
                    } else
                        return "";

                }
                , initEd: function () {
                    //gird初始化的后置事件 信息

                }
                , showDlgBefore: function () {
                }
                , changeEnd: function () {
                    //后置事件
                }
                , AddBefore: function () {
                    //表单发送前
                    AddOrUpdate();
                    return true;
                }
                , showDetailEnd: function (data) {//显示详细对话框之后
                    $("#txtbSCourseName").val(data.ICourseId + ':' + data.SCourseName);
                    $("#txtbSTeamName").val(data.ITeamId + ':' + data.STeamName);
                    $("#txtbSTeacharName").val(data.ITeacherId + ':' + data.STeacharCode + ':' + data.STeacharName);
                }
            };

            gdViewModel = new gridViewModel(options);

            gdViewModel.init();
            ko.applyBindings(gdViewModel);


            options.frmElement.validate({
                rules: {

                    txtbSCourseName: { maohao1: true },
                    txtbSTeamName: { maohao1: true },
                    txtbSTeacharName: { maohao2: true },

                },
                messages: {

                }
            });

            //输入课程名获取输入提示
            $("#txtbSCourseName").typeahead({
                source: function (query, process) {
                    $.ajax({
                        url: "/api/DeanCourse/GetAll",
                        type: "POST",
                        dataType: "Json",
                        async: true,
                    })
                    .done(function (data) {
                        var array = [];
                        for (i in data) {
                            array.push(data[i].Id + ':' + data[i].SCourseName + ':' + data[i].SCourseCode);
                        };
                        process(array);
                    })

                }
            });

            //输入学年学期获取输入提示
            $("#txtbSTeamName").typeahead({
                source: function (query, process) {
                    $.ajax({
                        url: "/api/DeanTerm/GetAll",
                        type: "POST",
                        dataType: "Json",
                        async: true,
                    })
                    .done(function (data) {
                        var array = [];
                        for (i in data) {
                            array.push(data[i].Id + ':' + data[i].STermName);
                        };
                        process(array);
                    })
                }
            });

            //输入教师姓名获取输入提示
            $("#txtbSTeacharName").typeahead({
                source: function (query, process) {
                    $.ajax({
                        url: "/api/Teachers/GetAll",
                        type: "POST",
                        dataType: "Json",
                        async: true,
                    })
                    .done(function (data) {
                        var array = [];
                        for (i in data) {
                            array.push(data[i].Id + ':' + data[i].STeaNo + ':' + data[i].STeaName);
                        };
                        process(array);
                    })
                }
            });

            var AddOrUpdate = function () {
                //获取选择的课程的相关信息
                var courseInfo = $("#txtbSCourseName").val().split(":");
                options.NodeValue().ICourseId = courseInfo[0];//课程ID
                options.NodeValue().SCourseName = courseInfo[1];//课程名
                sCourseCode = courseInfo[2];//课程编号

                //获取选择的学年学期相关信息
                var termInfo = $("#txtbSTeamName").val().split(":");
                options.NodeValue().ITeamId = termInfo[0];//学年学期ID
                options.NodeValue().STeamName = termInfo[1];//学年学期名

                //获取选择的教师的相关信息
                var teacherInfo = $("#txtbSTeacharName").val().split(":");
                options.NodeValue().ITeacherId = teacherInfo[0];//教师ID
                options.NodeValue().STeacharCode = teacherInfo[1];//教师工号
                options.NodeValue().STeacharName = teacherInfo[2];//教师姓名
            };
        });

    </script>

}




<!--/end grid code-->

